<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/8 0008
 * Time: 上午 11:59
 */

namespace App\Http\Controllers;


use App\Models\Gifts;
use App\Models\Order;
use Illuminate\Support\Facades\DB;

class DempController extends Controller
{
    public function index()
    {
//       $data = DB::select('SELECT * FROM `gifts` WHERE id =?',[9]);
//       $data = Gifts::select('id','name')->orderBy('id','desc')->distinct()->value('id');

//        $data = DB::table('order_invoices')->where('content->invoice_title','个人')->whereId('144')->get();
//        $data = DB::table('gifts')->where('nums',null)->union($dataa)->get();
//        $data = DB::table('goods')
//            ->join('goods_brands', function ($join) {
//                $join->on('goods.id', '=', 'goods_brands.goods_id')
//                    //->where('goods.id', '<', 230)
//                ;
//                })->where('goods.tenant_id','0')->where('goods.id', '<', 230)
//            ->get();


//        $data = Gifts::skip(5)->take(5)->get();
//        $data = Gifts::limit(5)->offset(5)->get();
//        $data = Gifts::paginate(5)->url(2);
//        $data = Gifts::findOrFail(1);
        $sdaya = [
            //'id'=>'9',
            'name'=>'cefsdshi',
            'tenant_id'=>'1004',
            'img'=>'/upload/images/store/2018-08-22/5b7cfd6fb3fbf.png',
        ];
        //$data = Gifts::where('id',9)->update($sdaya);
        $order = Order::find(1);
//        $data = Gifts::saveBy($sdaya);
//        $data = Gifts::get();
        dd($order);
//        $order = Gifts::get();
//        dd($data);
        //$data->orders()->save($order);
        dd($data->orders()->sync(['order_id'=>8]));
        $orderIds = [1,2,3,4,5];
        $data->orders()->sync($orderIds);
        dd($data);
//        $aa = new Gifts();

//        $data = $aa->create($sdaya);
        return $data;

    }

}
